{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/addons/builder/css/base.css" media="all">
<style>
    #table th,#table td{
        text-align: center;
    }
    .x-sort{
        height: 24px !important;
    }
    .layui-table thead{
        background: rgb(231, 238, 253,0.4);
        color: #515a6e;
    }
    .layui-table thead th{
        height: 28px;
        line-height: 28px;
    }

    .layui-table tbody td{
        height: 35px;
        line-height: 35px;
    }
    .layui-table .layui-form-switch{
        margin-top: initial;
    }
    .layui-btn+.layui-btn{
        margin-left: 0;
    }
</style>
<body>

<div class="layui-fluid layui-anim layui-leftbit">
    <div class="layui-card" style="padding-top: 5px">

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <a class="layui-btn layui-btn-normal layui-btn-sm layui-btn-radius" id="create">
                    <i class="layui-icon layui-icon-add-circle-fine"></i>备份
                </a>
                <a class="layui-btn layui-btn-danger layui-btn-sm layui-btn-radius clear">
                    <i class="layui-icon layui-icon-delete"></i>清空数据
                </a>

                <a class="layui-btn layui-btn-danger layui-btn-sm layui-btn-radius deletes">
                    <i class="layui-icon layui-icon-delete"></i>批量删除
                </a>

            </div>
            <table class="layui-table layui-form" id="table"  lay-size="sm">
                <thead>
                <tr>
                    <th style="width: 15px"><input type="checkbox" lay-filter="list_all" lay-skin="primary"/></th>
                    <th>文件名</th>
                    <th style="width: 140px">文件大小</th>
                    <th style="width: 140px">备份时间</th>
                    <th width="{:getBtnWidth('130')}px;">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="v"}
                <tr class="data_line" data_id="{$v.file}">
                    <td>{if $v.is_del}<input type="checkbox" lay-filter="list_checkbox" lay-skin="primary"
                                             value="{$v.file}"/>{/if}
                    </td>
                    <td>{$v.file}</td>
                    <td>{$v.size}</td>
                    <td>{:date('Y-m-d H:i:s',$v.create_time)}</td>
                    <td class="td-manage">
                        <a class="{:getBtnClass()} backup" data-file="{$v.file}" href="javascript:;">还原</a>
                        {if $v.is_del}<a class="{:getBtnClass('danger',true)} delete"
                                         data-file="{$v.file}">删除</a>{/if}
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>

    </div>
</div>
</body>
{include file="public/footer" /}
<script>
    $(function () {
        $('#create').click(function () {
            layerLoad()
            $.get("{:URL('Backup/add')}", function (data) {
                layer.closeAll();
                if (data.code == 1) {
                    notify.success("数据备份成功", 1500, function () {
                        window.location.reload();
                    });
                } else {
                    notify.error("数据备份失败");
                }
            }, 'json');
        })
        $('.backup').click(function () {
            var file = $(this).attr('data-file');
            layer.confirm('确认要还原吗？', function (index) {
                layerLoad()
                $.get(
                    "{:url('Backup/import')}",
                    {file: file},
                    function (data) {
                        layer.closeAll();
                        if (data.code == '1') {
                            notify.success(data.message, 1500, function () {
                                window.location.reload();//页面刷新
                            });
                        }else{
                            notify.error(data.message);
                        }
                    }, 'json'
                );
            });
        })
        $('.clear').click(function () {
            layer.confirm('确认要清空数据吗？', function (index) {
                layerLoad()
                $.get(
                    "{:url('Backup/clear')}",
                    function (data) {
                        layer.closeAll();
                        if (data.code == '1') {
                            notify.success(data.message, 1500, function () {
                                window.location.reload();//页面刷新
                            });
                        }else{
                            notify.error(data.message);
                        }
                    }, 'json'
                );
            });
        })
        $('.delete').click(function () {
            var file = [$(this).attr('data-file')];
            del(file);
        })
        $('.deletes').click(function () {

            var arr = [];
            $("[lay-filter=list_checkbox]:checked").each(function (i, e) {
                arr.push($(this).val());
            });
            console.log()
            if (arr.length < 1) {
                notify.warning('请选择要删除的文件');
                return;
            }
            del(arr);
        })
    })

    function del(file) {
        layer.confirm('确认要删除吗？', function (index) {
            $.get(
                "{:url('Backup/delete')}",
                {file: file},
                function (data) {

                    window.location.reload();
                }
            )
        })
    }
</script>
</html>